// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CXFormsElement2.
//   $Id$


#pragma once
#include "xformselement.h"
#include <DOM2Core.h>

#include "CComBSTRPtrList.h"
#define CXFORMSELEMENT2_EVENTS_LENGTH 3

class CXFormsElement2 :
	public CXFormsElement
{
public:
	CXFormsElement2(void);
	virtual ~CXFormsElement2(void);

	BEGIN_COM_MAP(CXFormsElement2)
		COM_INTERFACE_ENTRY2(IUnknown,IElementBehavior)
		//COM_INTERFACE_ENTRY_AUTOAGGREGATE(IID_INode,m_pDOM2NodeImpl.p,CLSID_Node)
		COM_INTERFACE_ENTRY_CHAIN(CXFormsElement)
	END_COM_MAP()

#ifdef _DEBUG
	ULONG InternalRelease( void)
	{
		ULONG l = __super::InternalRelease();
		return l;
	}

	ULONG InternalAddRef()
	{
		ULONG l = __super::InternalAddRef();
		return l;
	}
#endif

	// If v2 DOM2Events are used. 
	//STDMETHOD(dispatchEvent)(IDOMEvent * evt,long * bCancelled);
	HRESULT onfp_putvalue(BSTR sVal);
	HRESULT onfp_putfocus();
	HRESULT onfp_uirefresh();
	
	virtual HRESULT attachEvents(IHTMLElement2 * pEl2, CComBSTRPtrList * pEventList = 0);
	virtual HRESULT getXML(IXMLDOMNode ** ppXML);
	/// <summary>Set the inital state of the css classes for this element. This is called from within 
	/// CBoundNode::AddTarget() through the IBoundTarget::setInitialState().</summary>
	virtual HRESULT SetClassProperty(bool bEnabled, bool bReadOnly, bool bValid, bool bRequired);
	void setBindingToTarget(bool bBinding);
	inline HRESULT updateAppearance(void);
	virtual HRESULT ElementReady();
	virtual HRESULT render(); 

	virtual HRESULT get_valuechanging(BSTR* psValue);
	virtual HRESULT get_value(BSTR* psValue);// = 0;
	virtual HRESULT put_value(BSTR sValue);// = 0;
	virtual HRESULT put_navindex(BSTR bsValue);
	virtual HRESULT put_accesskey(BSTR bsValue);
	
	virtual HRESULT formControlInitialize();
	virtual HRESULT put_style(BSTR sWhere, BSTR sStyle);
	STDMETHOD(Detach)();
	virtual HRESULT UIExecScript(BSTR bsScript);
	virtual HRESULT UIExecFunction(BSTR bsFunctionName,DISPPARAMS * pParams,VARIANT * pvtResult,DISPID & dispid);
	virtual HRESULT focus();
	virtual HRESULT InitBehaviour();
protected:
	HRESULT resetSchemaTypeForUI(CComBSTR & sType);
	bool m_bPuttingValue;
private:
	bool m_bElementProcessed;
	HRESULT setSchemaTypeForUI(CComBSTR & sType);
	//CComPtr<INode> m_pDOM2NodeImpl;
	
	
	//array storing event cookies.
	//	these are the ids given to us by 
	//	RegisterEvent.
	long m_alEventCookies[CXFORMSELEMENT2_EVENTS_LENGTH];
	//The event cookies are assigned on an
	//	object-by-object basis, however, 
	//	the names can be static.
	static const CComBSTR* const sm_asEventNames[CXFORMSELEMENT2_EVENTS_LENGTH];

};

inline HRESULT CXFormsElement2::updateAppearance(void)
{
	return S_FALSE;
};
